package com.example.yml;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity  implements CompoundButton.OnCheckedChangeListener {
EditText name;
CheckBox cb_1,cb_2,cb_3,cb_4,cb_5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cb_1=findViewById(R.id.cb_1);
        cb_2=findViewById(R.id.cb_2);
        cb_3=findViewById(R.id.cb_3);
        cb_4=findViewById(R.id.cb_4);
        cb_5=findViewById(R.id.cb_5);
        cb_1.setOnCheckedChangeListener(this);
        cb_2.setOnCheckedChangeListener(this);
        cb_3.setOnCheckedChangeListener(this);
        cb_4.setOnCheckedChangeListener(this);
        cb_5.setOnCheckedChangeListener(this);

    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        boolean a=true;
        switch (compoundButton.getId()){
            case R.id.cb_1:

            case R.id.cb_2:

            case R.id.cb_3:

            case R.id.cb_4:
                if(!b){
                    a=false;
                }
                break;
            case R.id.cb_5:
                if(b){
                    cb_1.setChecked(true);
                    cb_2.setChecked(true);
                    cb_3.setChecked(true);
                    cb_4.setChecked(true);
                }else {
                    cb_1.setChecked(false);
                    cb_2.setChecked(false);
                    cb_3.setChecked(false);
                    cb_4.setChecked(false);
                }

                break;
        }
        if(cb_1.isChecked()&&cb_2.isChecked()&&cb_3.isChecked()&&cb_4.isChecked()){
            cb_5.setChecked(true);
        }
        if (!a){
            cb_5.setChecked(false);
        }
    }
}
